package webserver

import (
	"fmt"
	"github.com/astaxie/beego"
	"ktvserver/config"
	_ "ktvserver/webserver/routers"
	"log"
	//"path/filepath"
	//"runtime"
	"time"
)

var (
	// 是否启用的web端口
	EnableNewWebPort = false
)

func StartServerByPort(port int) {
	beego.HttpPort = port
	beego.EnableAdmin = false
	beego.SessionOn = true  // 启用session
	beego.EnableGzip = true // 启用gzip压缩
	beego.BeegoServerName = "ShiYouServer-" + config.Version
	beego.SessionName = fmt.Sprintf("my%d", port)

	if EnableNewWebPort {
		// 启用的WEB端口
		log.Printf("WebServer http://127.0.0.1:%d/\n", port)
		beego.Run()
	} else {
		// 复用原有的TCP端口
		beego.InitBeforeHttpRun()

		app := beego.BeeApp
		app.Server.Handler = app.Handlers
		app.Server.ReadTimeout = time.Duration(beego.HttpServerTimeOut) * time.Second
		app.Server.WriteTimeout = time.Duration(beego.HttpServerTimeOut) * time.Second

	}

}

/*
// add new function
func InitBeforeHttpRun() {
	initBeforeHttpRun()
}

*/
